package eiisan.guava;

import com.google.common.base.Splitter;
import org.junit.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalField;
import java.util.Date;
import java.util.List;

public class StringDemo {
    private SimpleDateFormat formatYMD = new SimpleDateFormat("yyyy-MM-dd");
    private SimpleDateFormat formatHM = new SimpleDateFormat("HH:mm");
    private SimpleDateFormat formatYMDHM = new SimpleDateFormat("yyyy-MM-dd HH:mm");

    @Test
    public void testSplit(){
//        String str = "1ss,null,s1,,1";
        String str = "1ss,null,    ,,  , ,, s1,,1";
        List<String> rs =  Splitter.on(",").omitEmptyStrings().splitToList(str);
        System.out.println("rs = " + rs);
    }

    @Test
    public void testDate() throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
        String startStr = "2021.7.2 12:00:00";
        String endStr = "2021.7.2 12:15:00";
        Date date = sdf.parse(startStr);;
        Date date2 = sdf.parse(endStr);
        boolean isAroundTime = isAroundTime(date, date2, 15);

        System.out.println(isAroundTime);


    }


    public boolean isAroundTime(Date sourceDate, Date targetDate, int minutes) {
        Long i = sourceDate.getTime() - targetDate.getTime();
        return minutes >= Math.abs(i/1000/60);
    }
}
